package com.swak.boot.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.swak.App;
import com.swak.boot.ApplicationProperties;
import com.swak.boot.Version;

/**
 * 系统配置 - 启动和关闭
 *
 * @author: lifeng
 * @date: 2020/4/1 12:38
 */
@Configuration
@EnableConfigurationProperties(ApplicationProperties.class)
public class AppAutoConfiguration {

	@Autowired
	private ApplicationContext context;
	@Autowired
	private ApplicationProperties properties;

	/**
	 * 系统
	 *
	 * @return APP
	 */
	@Bean
	public App app() {
		return new App().setContext(context) // 上下文
				.setSn(properties.getServerSn()) // 服务的序列号
				.setName(properties.getName()) // 应用名称
				.setVersion(Version.getVersion()) // 版本号
				.setSerialization(properties.getSerialization()) //序列化方式
				.build();
	}
}